from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait


class BasePage(object):
    """
    Base class which will be inherited by all Page Objects
    """

    def __init__(self,driver):
        self.driver = driver
    def wait_find_element(self,position_express:str,xpath_expression:str):
        """
        定位单个元素
        :param xpath_expression:
        :return:
        """
        return WebDriverWait(self.driver,10,0.5).until(
            lambda d:self.driver.find_element(position_express,xpath_expression)
        )
    def wait_find_elements(self,position_express:str,xpath_expression:str):
        """
        定位单个元素
        :param xpath_expression:
        :return:
        """

        return WebDriverWait(self.driver,10,0.5).until(
            lambda d:self.driver.find_elements(position_express,xpath_expression)
        )
    def goto_url(self,url):
        self.driver.get(url)
    def msg(self,position_express:str,xpath_expression:str):
        msg=WebDriverWait(self.driver,10,0.5).until(
            lambda d:self.driver.find_element(position_express,xpath_expression).text
        )
        return  msg